import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/avatar_role_name.dart';
import 'package:flutter_application_1/components/comment_like_read.dart';
import 'package:flutter_application_1/config/app_colors.dart';
import 'package:flutter_application_1/utils/utils.dart';

import '../models/video_model.dart';

class VideoCart extends StatelessWidget {
  final VideoItem videoItem;
  const VideoCart({Key? key, required this.videoItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 8),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _title(),
          SizedBox(height: 10),
          _cover(),
          SizedBox(height: 10),
          _bottom(),
        ],
      ),
    );
  }

  Widget _title() {
    return Text(
      videoItem.title,
      maxLines: 2,
      overflow: TextOverflow.ellipsis,
      style: TextStyle(
        color: AppColors.unactive,
        fontSize: 16,
      ),
    );
  }

  Widget _cover() {
    return AspectRatio(
      aspectRatio: 16 / 9,
      child: Stack(
        fit: StackFit.expand,
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: FadeInImage.assetNetwork(
              placeholder: "assets/images/common/lazy-1.png",
              image: videoItem.coverPictureUrl,
              fit: BoxFit.cover,
            ),
          ),
          Center(
            child: Image.asset(
              "assets/images/icons/play_plus.png",
              width: 50,
              height: 50,
              fit: BoxFit.cover,
            ),
          ),
          Positioned(
            right: 10,
            bottom: 10,
            child: Container(
              child: Text(
                secondsToFormat(videoItem.contentSeconds),
                style: TextStyle(
                  color: AppColors.un3active,
                  fontSize: 16,
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _bottom() {
    return Row(
      children: [
        Expanded(
          child: AvatarRoleName(
            coverPictureUrl: videoItem.user.coverPictureUrl,
            nickname: videoItem.user.nickname,
            type: videoItem.user.type,
          ),
        ),
        Expanded(
          child: CommentLikeRead(
            commentCount: videoItem.commentCount,
            thumbUpCount: videoItem.thumbUpCount,
            readCount: videoItem.readCount,
          ),
        ),
      ],
    );
  }
}
